/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Principal.java
 *
 * Created on 14-may-2009, 12:01:00
 */
package ejemplotiendawebswing;

import ejemplotiendaweb.controlador.PrincipalController;
import java.awt.HeadlessException;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author ccia
 */
public final class Principal extends javax.swing.JDialog {

    PrincipalController controlador;

    // Constructor sobre cargado
    public Principal(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();

     //   c = new PersonaDelegate();
        //System.out.println(c.getTodasPersonas().toString());

       // modelo = new ModeloTablaPersona(c.getTodasPersonas());
        //refControladorPantalla = new ControladorPantalla();


// Netbeans hae este trabajo

        this.setLocationRelativeTo(parent);
// Cargar los titulos del combo
        configuroTitulosCombo();
        //tablaCliente.setModel(modelo);
//oculto el campo id de la tablaCliente
       // tablaCliente.getColumnModel().removeColumn(tablaCliente.getColumnModel().getColumn(0));



    }

// COnstructor vacìo
  public Principal() {
        initComponents();
    }

    public void setControlador(PrincipalController controlador) {
        this.controlador = controlador;
    }


    /*private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
        cont.dialogoFamilias();
    } */

    public DefaultTableModel getModeloTabla() {
        return (DefaultTableModel) tablaCliente.getModel();
    }

    public JComboBox getComboFiltros() {
        return comboCriterioBuscar;
    }

    public void resetFiltros() {
        //comboCriterioBuscar.setText("");
    }


//*************** configura el combo de bùsqueda
    public void configuroTitulosCombo() {
        String[] titulo = {"Descripcion", "Detalle", "Precio", "Existencias", "Marca", "Modelo", "Familia"};
        // Cargo el combo
        comboCriterioBuscar.removeAllItems();
        for (int i = 0; i < titulo.length; i++) {
            comboCriterioBuscar.addItem(titulo[i]);
        }

    }

//*************** initComponents
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        txtBuscar = new javax.swing.JTextField();
        btBuscar = new javax.swing.JButton();
        comboCriterioBuscar = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaCliente = new javax.swing.JTable();
        jToolBar1 = new javax.swing.JToolBar();
        btAgregar = new javax.swing.JButton();
        btEliminar = new javax.swing.JButton();
        btModificar = new javax.swing.JButton();
        btImprimeUno = new javax.swing.JButton();
        btImprimeTodo = new javax.swing.JButton();
        btSalir = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        botonCOMPRA = new javax.swing.JButton();
        btRefrescar1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel1.setText("Tienda Virtual");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Seleccione el criterio a Buscar :"));

        jLabel2.setText("Introduzca el contenido a buscar :");

        txtBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtBuscarActionPerformed(evt);
            }
        });

        btBuscar.setText("Buscar");
        btBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btBuscarActionPerformed(evt);
            }
        });

        jLabel5.setText("Buscar por :");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addComponent(comboCriterioBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(43, 43, 43)
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addComponent(txtBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(60, 60, 60)
                .addComponent(btBuscar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(comboCriterioBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(txtBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btBuscar))
                .addContainerGap())
        );

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Registros encontrados"));

        tablaCliente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tablaCliente);

        jToolBar1.setRollover(true);

        btAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ejemplotiendawebswing/resources/add.png"))); // NOI18N
        btAgregar.setText("Agregar");
        btAgregar.setBorderPainted(false);
        btAgregar.setContentAreaFilled(false);
        btAgregar.setFocusable(false);
        btAgregar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btAgregar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btAgregar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAgregarActionPerformed(evt);
            }
        });
        jToolBar1.add(btAgregar);

        btEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ejemplotiendawebswing/resources/delete.png"))); // NOI18N
        btEliminar.setText("Eliminar");
        btEliminar.setBorderPainted(false);
        btEliminar.setContentAreaFilled(false);
        btEliminar.setFocusable(false);
        btEliminar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btEliminar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btEliminar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEliminarActionPerformed(evt);
            }
        });
        jToolBar1.add(btEliminar);

        btModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ejemplotiendawebswing/resources/pencil.png"))); // NOI18N
        btModificar.setText("Modificar");
        btModificar.setBorderPainted(false);
        btModificar.setContentAreaFilled(false);
        btModificar.setFocusable(false);
        btModificar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btModificar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btModificar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btModificarActionPerformed(evt);
            }
        });
        jToolBar1.add(btModificar);

        btImprimeUno.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ejemplotiendawebswing/resources/print.jpg"))); // NOI18N
        btImprimeUno.setText("Imprimir Uno");
        btImprimeUno.setBorderPainted(false);
        btImprimeUno.setContentAreaFilled(false);
        btImprimeUno.setFocusable(false);
        btImprimeUno.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btImprimeUno.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btImprimeUno.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btImprimeUno);

        btImprimeTodo.setText("Imprimir Todo");
        btImprimeTodo.setBorderPainted(false);
        btImprimeTodo.setContentAreaFilled(false);
        btImprimeTodo.setFocusable(false);
        btImprimeTodo.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btImprimeTodo.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jToolBar1.add(btImprimeTodo);

        btSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ejemplotiendawebswing/resources/delete_obj.gif"))); // NOI18N
        btSalir.setText("Salir");
        btSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalirActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ejemplotiendawebswing/resources/backward_enabled.gif"))); // NOI18N
        jButton3.setBorderPainted(false);
        jButton3.setContentAreaFilled(false);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ejemplotiendawebswing/resources/forward_enabled.gif"))); // NOI18N
        jButton4.setBorderPainted(false);
        jButton4.setContentAreaFilled(false);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel3.setText("Pag :");

        jLabel4.setText("de :");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(340, Short.MAX_VALUE)
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(126, 126, 126)
                .addComponent(btSalir)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 739, Short.MAX_VALUE)
                .addGap(9, 9, 9))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 737, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3)
                        .addComponent(jLabel4)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btSalir)
                    .addComponent(jButton3))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        botonCOMPRA.setText("Agregar al Carrito");
        botonCOMPRA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCOMPRAActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(47, 47, 47)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(botonCOMPRA)))
                .addContainerGap(41, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(24, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botonCOMPRA)
                        .addGap(88, 88, 88))))
        );

        btRefrescar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ejemplotiendawebswing/resources/webapp_security_role.gif"))); // NOI18N
        btRefrescar1.setText("Ver por Familias");
        btRefrescar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRefrescar1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(btRefrescar1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 508, Short.MAX_VALUE)
                        .addComponent(jLabel1)
                        .addGap(373, 373, 373))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(btRefrescar1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtBuscarActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtBuscarActionPerformed

    private void btAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAgregarActionPerformed
        controlador.crearProducto();
}//GEN-LAST:event_btAgregarActionPerformed

    private void btEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEliminarActionPerformed
        int opcion = JOptionPane.showConfirmDialog(null, "Seguro desea Borrar el Registro?", "Tienda Virtual", JOptionPane.OK_CANCEL_OPTION);
        if (opcion == 0) {
            controlador.eliminarProducto(tablaCliente.getSelectedRow());
        }
    }//GEN-LAST:event_btEliminarActionPerformed

    private void btModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btModificarActionPerformed
        // Determina la fila y columna seleccionada y la almacena en una variable
        int filaSeleccionada = tablaCliente.getSelectedRow();//numero fila seleccionada
        int columnaSeleccionada = tablaCliente.getSelectedColumn();//numero de columna seleccionada NO ME INTERESA
        // Como la tabla comienza en CERO , -1 es tomado como NADA, entonces el mensaje de error
        if (filaSeleccionada == -1) {
            javax.swing.JOptionPane.showMessageDialog(this, "Seleccione un producto de la lista", "Error", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        } // Entonces si pinchò alguna fila porque es distinto de -1
        // Recupero el NRO de la fila y la COLUMNA CERO
        // La columna CERO tiene el ID escondido
        else {
            controlador.editarProducto(tablaCliente.getSelectedRow());
        }
    }//GEN-LAST:event_btModificarActionPerformed

    private void btBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btBuscarActionPerformed
        try {
            if (txtBuscar.getText().equals("")) {
                javax.swing.JOptionPane.showMessageDialog(this, "Ingrese el contenido a buscar", "Error", javax.swing.JOptionPane.INFORMATION_MESSAGE);
            }
            if (comboCriterioBuscar.getSelectedItem().equals("NOMBRE")) {
             //   tablaCliente.setModel(new ModeloTablaPersona(c.buscarXNombre(txtBuscar.getText())));
                tablaCliente.getColumnModel().removeColumn(tablaCliente.getColumnModel().getColumn(0));
                txtBuscar.setText("");
            }
            if (comboCriterioBuscar.getSelectedItem().equals("APELLIDO")) {
               // tablaCliente.setModel(new ModeloTablaPersona(c.buscarXNombre(txtBuscar.getText())));
                tablaCliente.getColumnModel().removeColumn(tablaCliente.getColumnModel().getColumn(0));
                txtBuscar.setText("");
            }
            if (comboCriterioBuscar.getSelectedItem().equals("DNI")) {
            //    tablaCliente.setModel(new ModeloTablaPersona(c.buscarXDNI(Long.parseLong(txtBuscar.getText()))));
                tablaCliente.getColumnModel().removeColumn(tablaCliente.getColumnModel().getColumn(0));
                txtBuscar.setText("");
            }
            if (comboCriterioBuscar.getSelectedItem().equals("CALLE")) {
            }
        } catch (HeadlessException e) {
            JOptionPane.showMessageDialog(this, "Error inesperado");
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this, "Cuando busca por dni, ingresar solo números");
        }
}//GEN-LAST:event_btBuscarActionPerformed

    private void btSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalirActionPerformed
        this.dispose();
}//GEN-LAST:event_btSalirActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton4ActionPerformed

    private void btRefrescar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRefrescar1ActionPerformed
       controlador.dialogoFamilias();
    }//GEN-LAST:event_btRefrescar1ActionPerformed

    private void botonCOMPRAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCOMPRAActionPerformed
        controlador.comprar( tablaCliente.getSelectedRow());
       
    }//GEN-LAST:event_botonCOMPRAActionPerformed

    public void actualizarTabla() {
        // LImpia la tabla
      //  tablaCliente.setModel(new ModeloTablaPersona(c.getTodasPersonas()));


    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                Principal dialog = new Principal(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    /*public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }*/
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonCOMPRA;
    private javax.swing.JButton btAgregar;
    private javax.swing.JButton btBuscar;
    private javax.swing.JButton btEliminar;
    private javax.swing.JButton btImprimeTodo;
    private javax.swing.JButton btImprimeUno;
    private javax.swing.JButton btModificar;
    private javax.swing.JButton btRefrescar1;
    private javax.swing.JButton btSalir;
    private javax.swing.JComboBox comboCriterioBuscar;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JTable tablaCliente;
    private javax.swing.JTextField txtBuscar;
    // End of variables declaration//GEN-END:variables
}
